package com.qxt.prize.models;

import com.qxt.prize.Constants;
import lombok.Data;
import top.moirae.core.AbstractOption;
import top.moirae.core.ErrorMessage;
import top.moirae.security.models.Rule;
import top.moirae.security.models.User;

import java.math.BigDecimal;
import java.time.LocalDateTime;

/**
 * 通用奖品表(Prize)表数据库访问层
 */
@Data
public class Prize {

    public static final String ENTITY_NAME = "PRIZE";

    private Long id;
    private String name; // 奖品名称
    private String description; // 奖品描述
    private BigDecimal value; // 奖品价值
    private Long quantity; // 奖品库存数量
    private Type type; // 奖品类型
    private String cover; // 奖品展示资源
    private LocalDateTime publishAt; // 发布时间
    private LocalDateTime createAt; // 创建时间
    private User createBy; // 创建人

    public enum Type {
        REAL, // 真实奖品
        VIRTUAL // 虚拟奖品
    }

    public static class Rules {
        public static Rule.Constant READ = new Rule.Constant(Constants.MODULE, ENTITY_NAME, "READ");
        public static Rule.Constant CREATE = new Rule.Constant(Constants.MODULE, ENTITY_NAME, "CREATE");
        public static Rule.Constant UPDATE = new Rule.Constant(Constants.MODULE, ENTITY_NAME, "UPDATE");
        public static Rule.Constant DELETE = new Rule.Constant(Constants.MODULE, ENTITY_NAME, "DELETE");
    }

    public static class Errors {
        public static final ErrorMessage NOT_FOUND = new ErrorMessage(Constants.MODULE, ENTITY_NAME, "NOT_FOUND");
        public static final ErrorMessage NOT_INVENTORY = new ErrorMessage(Constants.MODULE, ENTITY_NAME, "NOT_INVENTORY");
    }

    public AbstractOption<String> getCover() {
        return AbstractOption.apply(cover);
    }

}

